home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 423_01 / rdcf / dosfiles.doc < prev    next >
Encoding:
Text File  |  1993-01-14  |  26.1 KB  |  560 lines

  1.                      A Description of the DOS File System
  2.  
  3.                             by Philip J. Erdelsky
  4.                           PLAIN VANILLA CORPORATION
  5.                             CompuServe 75746,3411
  6.                       InterNet 75746.3411@compuserve.com
  7.  
  8.                                January 15, 1993
  9.  
  10.                  Copyright (c) 1993 Plain Vanilla Corporation
  11.  
  12.  
  13. 1. Introduction
  14. ---------------
  15.  
  16. The DOS file system is used not only by IBM PC's and compatibles, but also by
  17. some standalone word processors that use diskettes and by a number of other
  18. devices. Even computer systems that normally use a different file system, such
  19. as UNIX-based workstations, also have the ability to read and write diskettes
  20. in DOS format. All of these uses together make the DOS file system the single
  21. most widely used file system in the world.
  22.  
  23. The file system has evolved a great deal since its origin in DOS 1.0. The
  24. version described here is essentially that used by DOS 3.3. The large
  25. partitions used by DOS 4.0 and later versions of DOS are not included.
  26.  
  27. This description was written in conjunction with version 2.0 of the Plain
  28. Vanilla Reentrant DOS-Compatible File System, an implementation of the basic
  29. DOS file system written in portable C and distributed as free software.
  30.  
  31. There are a number of details regarding the DOS file system that are
  32. undocumented. Some of them have been filled in by experimentation; others are
  33. simply described as undefined;
  34.  
  35. 2. Block Devices
  36. ----------------
  37.  
  38. A DOS file system resides on what is generally called a block device.  This is
  39. usually a disk of some kind, but it may also be a part of regular or extended
  40. memory that has been configured as a RAM disk.
  41.  
  42. A block device stores information in sectors of equal size.  The most common
  43. sector size is 512 bytes, which is used by all standard DOS floppy diskettes,
  44. but some RAM disks and hard disks may use sectors containing 128, 256 or 1024
  45. bytes.
  46.  
  47. The sectors are numbered in a very simple way.  Each sector has a logical sector
  48. number.  The smallest logical sector number is zero, and the largest logical
  49. sector number is one less than the number of sectors.  Every logical sector
  50. number between these limits is assigned to one other sector.  There are no gaps
  51. in the numbering system.
  52.  
  53.  
  54. 3. Mapping Sides and Tracks
  55. ---------------------------
  56.  
  57. The logical sector numbering system usually hides some complexities that must
  58. be handled by the disk controller hardware, the disk driver software or both.
  59. The sectors on a disk are arranged into concentric circles called tracks.  Most
  60. floppy disks have tracks on both sides.  A hard disk has more than two sides,
  61. because it consists of two or more disks, rotating in unison on the same
  62. spindle.
  63.  
  64. Some disk controllers, especially hard disk controllers, accept logical sector
  65. numbers and make all conversions internally; but this is not always the case.
  66.  
  67. To read or write a sector, the disk controller first moves a reading and
  68. writing device, called a head, back or forth until it is positioned over the
  69. track containing the desired sector.  If the disk has tracks on more than one
  70. side, there is head for each side of the disk, and they move together.  The
  71. disk controller selects the proper head by electronic switching.  Finally, the
  72. disk controller waits until the disk rotation brings the desired sector under
  73. the head.  Then it reads or writes the sector.
  74.  
  75. To convert a logical sector number L into the corresponding side, track and
  76. sector numbers, the controller (or the software driver) usually needs the
  77. following three numbers:
  78.  
  79.      N = the number of sectors per track,
  80.      T = the number of tracks per side, and
  81.      S = the number of sides.
  82.  
  83. The tracks are usually numbered from 0 to T-1, with track 0 on the outside and
  84. track T-1 on the inside.  This puts the most frequently accessed sectors (those
  85. with low logical sector numbers) on the outside of the disk, where sectors are
  86. largest and the disk is the most reliable.
  87.  
  88. The sides are usually numbered from 0 to S-1, in an order determined by the
  89. hardware design.
  90.  
  91. The sectors in a single track are numbered from 1 to N, where the disk rotation
  92. carries them under a head in order of increasing sector number.  The numbering
  93. starts with 1, not 0.  The reason for this odd convention is not clear, but it
  94. is followed by a number of floppy disk drives, including the ones usually used
  95. with DOS-based computers.
  96.  
  97. The assignment of logical sector numbers to sectors on a disk follows a simple
  98. scheme with a straightforward object -- to minimize access time when the
  99. sectors are read or written in order of ascending logical sector numbers.  This
  100. usually means minimizing the number of times the heads must be moved, since
  101. this is by far the slowest kind of disk operation.
  102.  
  103. The formulas are as follows, where A rem B means the remainder when A is
  104. divided by B:
  105.  
  106.     sector number = L rem N + 1
  107.     side number = (L/N) rem S
  108.     track number = (L/N) / S
  109.  
  110. Logical sector number 0 is sector 1 in track 0 on side 0.  Since this sector
  111. can always be located without knowing the disk structure, it is often used to
  112. store information about the disk structure. This is important for floppy disks,
  113. which are removable.  Many floppy disk drives can accommodate disks with more
  114. than one format.  The file system codecan read logical sector 0 to find out
  115. how to locate other sectors.
  116.  
  117. As the logical sector number increases, the heads must be moved only when the
  118. track number increases.  This does not happen until all sectors with a
  119. particular track number have been accessed.
  120.  
  121. The number of tracks is needed only to check the track number to see whether it
  122. is in range.  This is advisable in some cases because some disk drives may be
  123. damaged if an attempt is made to move the heads beyond their normal range.
  124.  
  125.  
  126. 4. Handling Bad Sectors
  127. -----------------------
  128.  
  129. On any large hard disk, there are apt to be some bad spots.  Some hard disk
  130. controllers can remap the bad spots and make the disk appear to be a perfect
  131. disk with a slightly smaller capacity.  This is usually done during low-level
  132. formatting.
  133.  
  134. However, floppy disk controllers and some hard disk controllers cannot do this.
  135. To handle most cases of this kind, the DOS file system can be set up so that
  136. some sectors are marked as bad.  No DOS file information will be written into
  137. bad sectors.  This lowers the disk capacity, but it makes imperfect disks
  138. usable.  This is usually done when the disk is formatted.
  139.  
  140. If there is a bad sector in a critical area of the disk, such as the part that
  141. indicates which sectors are bad, the disk cannot be used to hold a DOS file
  142. system.  Fortunately, the critical area of a disk is quite small, so this is
  143. quite unlikely.
  144.  
  145.  
  146. 5. Disk Partitions
  147. ------------------
  148.  
  149. The original DOS file system used 16-bit logical sector numbers, so it could
  150. handle only file systems with at most 65535 sectors, or 32 megabytes when
  151. 512-byte sectors were used.  This was the infamous 32-megabyte barrier.  DOS
  152. could use a disk with more than 65535 sectors, but it could use only 65535
  153. sectors for its file system.
  154.  
  155. A simple solution to this problem is to divide the disk into two or more
  156. partitions, each of which contains no more than 65535 sectors, and to treat
  157. each partition as though it were a separate disk.
  158.  
  159. DOS 4.00 and later versions of DOS can use 32-bit logical sector numbers, so
  160. they can handle larger partitions.  This would seem to imply an 8-terabyte
  161. maximum, but other limitations make the practical maximum smaller than that.
  162.  
  163. This document covers only partitions of 32 megabytes or less that use 16-bit
  164. logical sector numbers.
  165.  
  166.  
  167. 6. The Layout of a DOS Disk
  168. ---------------------------
  169.  
  170. The sectors of a DOS disk are divided into the following groups, which are
  171. listed in order of increasing logical sector numbers:
  172.  
  173.      RESERVED SECTORS
  174.      FILE ALLOCATION TABLES
  175.      ROOT DIRECTORY
  176.      DATA AREA
  177.      HIDDEN SECTORS
  178.  
  179. The groups are described in detail in the following sections.
  180.  
  181.  
  182. 7. Reserved Sectors
  183. -------------------
  184.  
  185. The first reserved sector, which is always logical sector 0, is also called the
  186. bootstrap sector.
  187.  
  188. Here is what is in a 512-byte bootstrap sector:
  189.  
  190.      byte(s)  contents
  191.      -------  -------------------------------------------------------
  192.      0-2      first instruction of bootstrap routine
  193.      3-10     OEM name
  194.      11-12    number of bytes per sector
  195.      13       number of sectors per cluster
  196.      14-15    number of reserved sectors
  197.      16       number of copies of the file allocation table
  198.      17-18    number of entries in root directory
  199.      19-20    total number of sectors
  200.      21       media descriptor byte
  201.      22-23    number of sectors in each copy of file allocation table
  202.      24-25    number of sectors per track
  203.      26-27    number of sides
  204.      28-29    number of hidden sectors
  205.      30-509   bootstrap routine and partition information
  206.      510      hexadecimal 55
  207.      511      hexadecimal AA
  208.  
  209. Two-byte fields are always arranged in "little endian" order, with the less
  210. significant byte first.  Notice that some two-byte fields are not aligned on
  211. even addresses.  This may require special treatment by CPU's such as the
  212. Motorola 68000, which cannot directly access words at odd addresses.
  213.  
  214. The first instruction of the bootstrap routine is always a jump instruction
  215. that transfers control to the bootstrap routine in bytes 30-509.
  216.  
  217. The OEM name is usually the version of DOS or the name of the utility that was
  218. used to format the disk, represented by eight ASCII characters.  It may even be
  219. completely blank.  DOS apparently makes no use of the OEM name.
  220.  
  221. The total number of reserved sectors, including the bootstrap sector, is
  222. specified by the contents of bytes 14 and 15.  Reserved sectors other than the
  223. bootstrap sector are not used by DOS.  Most DOS disks have only one reserved
  224. sector, but a larger number may be used to reserve space for a non-DOS
  225. partition or to cause DOS to avoid one or more bad sectors.
  226.  
  227. For most 5-1/4 inch and 3-1/2 inch diskettes, the media descriptor byte conveys
  228. some the of same information redundantly:
  229.  
  230.    size                              5-1/4 5-1/4 5-1/4 5-1/4 5-1/4 3-1/2 3-1/2
  231.    density (D = double, H = high)      D     D     D     D     H     D     H
  232.    sides                               1     1     2     2     2     2     2
  233.    media descriptor byte              FE    FC    FF    FD    F9    F9    F0
  234.    bytes per sector                  512   512   512   512   512   512   512
  235.    sectors per cluster                 1     1     2     2     1     2     1
  236.    reserved sectors                    1     1     1     1     1     1     1
  237.    copies of file allocation table     2     2     2     2     2     2     2
  238.    entries in root directory          64    64   112   112   224   112   224
  239.    total sectors                     320   360   640   720  2400  1440  2880
  240.    sectors per file allocation table   1     2     1     2     7     3     9
  241.    sectors per track                   8     9     8     9    15     9    18
  242.    hidden sectors                      0     0     0     0     0     0     0
  243.  
  244. In addition, the media descriptor byte is repeated in the file allocation
  245. table, which is described below.
  246.  
  247. On diskettes formatted with only 8 sectors per track, the information given in
  248. bytes 3-29 is absent, and DOS must examine the media descriptor byte in the
  249. file allocation table to determine the exact disk format.
  250.  
  251. What DOS will do with a diskette that contains nonstandard but consistent
  252. parameters in its bootstrap sector is undefined. In some cases it will read
  253. and write the diskette properly; in other cases it will not.
  254.  
  255.  
  256. 8. File Allocation Tables
  257. -------------------------
  258.  
  259. The sectors immediately after the last reserved sector hold one or more copies
  260. of the file allocation table (sometimes called the FAT).  The number of copies
  261. is specified by byte 16 in the bootstrap sector, and the number of sectors in
  262. each copy is specified by bytes 22 and 23 in the bootstrap sector.
  263.  
  264. DOS uses only the first copy of the file allocation table, but it updates other
  265. copies, if any, to keep them identical to the first copy.  Then if the first
  266. copy develops a bad sector, a special file recovery program can be used to
  267. retrieve the information from another copy.
  268.  
  269. Most floppy and hard disks contain two copies of the file allocation table.
  270. Most RAM disks contain only one because RAM is a much more reliable medium.
  271.  
  272. Versions of DOS before 3.00 used a file allocation table with 12-bit entries.
  273. Each group of three consecutive bytes contains two 12-bit entries, arranged as
  274. follows:
  275.  
  276.     The first byte contains the eight least significant bits of the first
  277.     entry.
  278.  
  279.     The four least significant bits of the second byte contain the four most
  280.     significant bits of the first entry.
  281.  
  282.     The four most significant bits of the second byte contain the four least
  283.     significant bits of the second entry.
  284.  
  285.     The third byte contains the eight most significant bits of the second
  286.     entry.
  287.  
  288. In other words, if UV, WX and YZ are the hexadecimal representations of the
  289. three consecutive bytes, then the entries are WUV and YZX, respectively.
  290.  
  291. This odd arrangement is actually quite easy to implement in 8086 assembly
  292. language.  Yes, a file allocation table entry can be split between sectors.
  293.  
  294. A file allocation table with 12-bit entries is suitable for floppy diskettes,
  295. but proved inadequate for hard disk partitions, even those within the
  296. 32-megabyte limit.  With DOS 3.0, an alternative format with 16-bit entries was
  297. introduced.  A 16-bit entry occupies two consecutive bytes, stored in "little
  298. endian" order, with the less significant byte first.
  299.  
  300. The file allocation table entries are numbered consecutively.  Entry 0 (the
  301. first entry) contains the media descriptor byte (byte 21 in the bootstrap
  302. sector), padded at the more significant end with ones to make it a 12-bit or
  303. 16-bit value.  Entry 1 contains either 12 or 16 ones.
  304.  
  305. For file allocation purposes, the data area of the disk is divided into a
  306. number of clusters.  Each cluster is the same size, and consists of the number
  307. of consecutive sectors specified in byte 13 of the bootstrap sector.
  308.  
  309. The clusters are numbered consecutively, starting with cluster number 2, which
  310. lies at the beginning of the data area.
  311.  
  312. Each entry in the file allocation table, except entries 0 and 1, is associated
  313. with the cluster with the same number as the entry.  This is quite consistent,
  314. because there are no clusters with number 0 or 1.
  315.  
  316. The contents of each such entry are interpreted as follows:
  317.  
  318.   contents in hexadecimal
  319.      12-bit   16-bit        meaning
  320.      -------  ---------     ---------------------------------------------------
  321.      000      0000          cluster is unassigned and available
  322.      001      0001          invalid entry
  323.      002-FEF  0002-FFEF     cluster is assigned, contents is the number of
  324.                               the next cluster in the same file or subdirectory
  325.      FF0-FF6  FFF0-FFF6     reserved
  326.      FF7      FFF7          cluster contains a bad sector
  327.      FF8-FFF  FFF8-FFFF     cluster is the last cluster assigned to a file
  328.                               or subdirectory
  329.  
  330. Whether 12-bit or 16-bit entries are used depends on the number of clusters in
  331. the data area.  If the range from 002 to FEF is sufficient to number them all,
  332. 12-bit entries are used.  Otherwise, 16-bit entries are used.
  333.  
  334. Notice that the restrictions on cluster size and the number of clusters put an
  335. upper limit on the partition size.
  336.  
  337. Each subdirectory, and each file that contains at least one byte of data, is
  338. associated with a chain of file allocation table entries, one for each cluster.
  339. The directory entry for the file or subdirectory, which is described below,
  340. contains the number of the first cluster.  The entry for each cluster other
  341. than the last cluster contains the number of the next following cluster.  The
  342. entry for the last cluster contains a value in the range FF8-FFF or FFF8-FFFF,
  343. which marks the end of the chain.
  344.  
  345.  
  346. 9. Root Directory
  347. -----------------
  348.  
  349. The root directory contains one 32-byte entry for each file in the root
  350. directory of the disk.  If the disk has a volume label, the root directory also
  351. contains a 32-byte entry for that.
  352.  
  353. The maximum number of root directory entries is specified in bytes 17 and 18 of
  354. the bootstrap block.  This number, together with the sector size, determines
  355. the number of sectors allocated to the root directory.
  356.  
  357. The field in bytes 17 and 18 of the bootstrap sector are always chosen so the
  358. number of root directory sectors is a whole number. What DOS will do otherwise
  359. is undefined.
  360.  
  361.  
  362. 10. The Data Area and Hidden Sectors
  363. ------------------------------------
  364.  
  365. The total number of sectors given in bytes 19 and 20 of the bootstrap sector
  366. includes all reserved sectors and all sectors in the root directory, the data
  367. area and all copies of the file allocation table.  It does not include the
  368. hidden sectors.  The size of the data area is not given directly, but it can be
  369. calculated from this information.  Apparently it must be an exact multiple of
  370. the cluster size. What DOS will do otherwise is undefined.
  371.  
  372. The total number of sectors, plus the number hidden sectors given in bytes
  373. 28-29 of the bootstrap sectors, is the true total number of sectors in the
  374. partition.  This is equal to the product of the number of sectors per track,
  375. the number of tracks per side, and the number of sides.  The number of tracks
  376. per side is not given, but it can be easily calculated from this information.
  377.  
  378. Usually, the hidden sectors are simply a few leftover sectors that could not be
  379. included in the data area because of various format constraints, but a large
  380. number of hidden sectors could be used to conceal a second partition.
  381.  
  382.  
  383. 11. Directory Structure
  384. -----------------------
  385.  
  386. Each directory entry, whether in the root directory or in a subdirectory,
  387. contains the following fields:
  388.  
  389.      byte(s)  contents
  390.      -------  ----------------------------------------------------
  391.      0-7      file name or first 8 characters of volume name
  392.      8-10     file extension or last 3 characters of volume name
  393.      11       attribute byte
  394.      12-21    unused
  395.      22-23    time
  396.      24-25    date
  397.      26-27    number of first cluster
  398.      28-31    number of bytes in file, or zero for subdirectory or
  399.                 volume label
  400.  
  401. The bits in the attribute byte determine the type of entry as follows (bit 7 is
  402. the most significant bit):
  403.  
  404.      bit  meaning if bit = 1
  405.      ---  ---------------------------------------
  406.       7   unused
  407.       6   unused
  408.       5   file has been changed since last backup
  409.       4   entry represents a subdirectory
  410.       3   entry represents a volume label
  411.       2   system file
  412.       1   hidden file
  413.       0   read-only
  414.  
  415. If the entry represents a subdirectory, bit 4 is set and all other bits are
  416. unused. If the entry represents a volume label, bit 3 is set and other bits are
  417. unused.
  418.  
  419. Since DOS file names are case-insensitive, the file name and extension contain
  420. no lower-case (small) letters.  They are always converted to the corresponding
  421. capital letters before writing them to the disk. What DOS will do if it finds
  422. small letters in a file name or extension in a directory entry is undefined.
  423.  
  424. The file name and extension are padded with ASCII blanks (hexadecimal 20) at
  425. the end if necessary to fill their respective fields.
  426.  
  427. Subdirectory names and extensions follow the same rules.
  428.  
  429. A volume name, however, is case-sensitive, and small letters are permitted.
  430. The name is always 11 characters long, and is apparently also padded with
  431. blanks to fill out its field.
  432.  
  433. When a subdirectory is created, or when a file or volume label is created or
  434. modified, DOS writes the current time and date into the time and date fields.
  435.  
  436. The time field is a two-byte value, stored in "little endian" order, with the
  437. less significant byte first.  Here is its format (bit 15 is the most
  438. significant bit):
  439.  
  440.      bits   contents
  441.      -----  ---------------------
  442.      15-11  hour (0-23)
  443.      10-5   minute (0-59)
  444.      4-0    double seconds (0-29)
  445.  
  446. Since there are not enough bits in the time field to express the time to the
  447. nearest second, the time is first rounded or truncated to the nearest even
  448. second.  The resulting seconds field is divided by 2 and written into bits 4-0.
  449. (Whether DOS actually uses rounding or truncation undefined, but it scarcely
  450. matters.)
  451.  
  452. The date field is a two-byte value, stored in "little endian" order, with the
  453. less significant byte first.  Here is its format (bit 15 is the most
  454. significant bit):
  455.  
  456.      bits   contents
  457.      -----  -----------------------------------------------
  458.      15-9   years elapsed since 1980 (0-127)
  459.      8-5    month (1=January, 2=February, ..., 12=December)
  460.      4-0    day (1-31)
  461.  
  462. Hence the DOS world began on January 1, 1980 at 00:00:00 and will end on
  463. December 31, 2107 at 23:59:58.
  464.  
  465. The very first byte of a directory entry has another function.  If it is
  466. hexadecimal E5, the entry represents a deleted file, subdirectory or volume
  467. label.  All other parts of the entry are valid and represent the status of the
  468. entry just before it was deleted.  If the first byte is zero (not an ASCII
  469. zero, which has the value hexdecimal 30, but an ASCII NUL), the entry is a
  470. terminating entry.  It has never been used since the directory was created, and
  471. there are no entries after it in the same directory.
  472.  
  473. When DOS 3.0 came along, characters from the IBM extended character set were
  474. permitted in file names and extensions.  Unfortunately, this created an
  475. ambiguity for hexadecimal E5, which represents an IBM extended character and
  476. also represents a deleted entry.  For compatiblity between DOS 3.0 and disks
  477. formatted under previous versions of DOS, DOS 3.0 converts the extended
  478. character represented by hexadecimal E5 into 05 before writing it to the
  479. directory entry when it appears as the first character of a file name.
  480. Presumably, DOS gives the same treatment to the first character of a volume
  481. label.
  482.  
  483. If a file contains no data, bytes 28-31 (number of bytes in file) are zero,
  484. which is quite logical.  However, bytes 26 and 27 (number of first cluster) are
  485. also zero, although FFF8 would probably have been more logical.
  486.  
  487. Bytes 28-31 (number of bytes in file) for a subdirectory entry are always zero.
  488. The length of a subdirectory is not recorded in its directory entry.  However,
  489. a subdirectory always contains at least one cluster.  Its length can be
  490. determined only by examining the chain of file allocation table entries.
  491.  
  492. The first two directory entries in a subdirectory are always the special
  493. subdirectories "." and "..", respectively.  Their time and date fields are the
  494. same as those of their parent (the subdirectory in which they lie).  The first
  495. cluster number of the subdirectory "." is also the same as that of its parent.
  496. The first cluster number of the subdirectory ".." is the same as that of the
  497. parent of its parent, or zero if the parent or its parent is the root
  498. directory.
  499.  
  500. Unused fields in a directory entry are set to zeros. What DOS will do
  501. otherwise is undefined.
  502.  
  503. Also undefined is what DOS will do if it finds a volume label in a
  504. subdirectory, or if if fails to find the special subdirectories "." and "..".
  505.  
  506.  
  507. 12. Directory Protocol
  508. ----------------------
  509.  
  510. When a disk is formatted, every entry in the root directory is a terminating
  511. entry.
  512.  
  513. When a subdirectory is created, it is immediately given one cluster.  (If there
  514. are no free clusters, a subdirectory cannot be created and the operation
  515. fails.)  The first two entries are filled with appropriate information for the
  516. special subdirectories "." and "..".  All other entries become terminating
  517. entries.
  518.  
  519. There cannot be two entries in the same directory with same name and extension
  520. unless they are deleted entries or one is a volume label and the other is not a
  521. volume label.  If the creation of a new file or subdirectory would cause a
  522. conflict, DOS usually fails the operation.  However, if a new file is created
  523. with the same name and extension as an existing file in the same directory, and
  524. the file mode permits, the new entry will simply replace the old one.  A new
  525. volume label in the root directory simply replaces the old one, if any.
  526.  
  527. When an entry is deleted, its first byte is replaced by hexedecimal E5 to mark
  528. it as deleted.  The rest of the entry is left unchanged.  If the entry
  529. represented a file or subdirectory, all clusters associated with it are marked
  530. as empty in the file allocation table.  The data in the clusters is not erased.
  531. Other entries in the directory are not moved to fill the gap.  In fact, so much
  532. information is left intact that a special utility may be able to restore almost
  533. all of the deleted file, subdirectory or volume label if it is invoked
  534. immediately, before anything else is written to the disk.  The first character
  535. of the name is truly lost, but other information remains on the disk and can be
  536. restored if it can be accurately located.
  537.  
  538. When a new entry is added to a directory, it is put in the first available
  539. location.  If the directory contains any deleted entries, the new entry
  540. replaces the first deleted entry.  Otherwise, the new entry replaces the first
  541. terminating entry.
  542.  
  543. If the directory contains no deleted or terminating entry, what happens next
  544. depends on whether it is the root directory or a subdirectory.  If it is the
  545. root directory, the operation fails because the root directory cannot be
  546. lengthened.  Otherwise, the directory is lengthened by adding another cluster
  547. to its allocation chain in the the file allocation table.  If there are no free
  548. clusters, the operation fails.  Otherwise, the new entry is the first entry
  549. in the new cluster, and all other entries in the cluster become terminating
  550. entries.
  551.  
  552. After a number of insertions and deletions, a directory can become quite
  553. fragmented.  The directory search time can be increased substantially if there
  554. are a lot of deleted entries, especially near the beginning of the directory.
  555. Special utilities are available to clean up fragmented directories, although
  556. they may make it difficult or even impossible to restore deleted files or
  557. subdirectories.
  558.  
  559.  
  560.